package com.duoduo.admin.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.duoduo.common.jpa.service.CommonService;
import com.duoduo.admin.api.dto.SysLogDTO;
import com.duoduo.admin.entity.SysLog;
import com.duoduo.admin.repository.SysLogRepository;

import jakarta.persistence.criteria.Predicate;

@Service
public class SysLogService extends CommonService<SysLogDTO, SysLog, Long>{

	@Autowired
	private SysLogRepository sysLogRepository;

	@Override
	public Specification<SysLog> getWhere(final SysLogDTO request) {
		return (root, query, cb) -> {
			final List<Predicate> predicate = new ArrayList<Predicate>();
			if(request.getId()!=null) {
				predicate.add(cb.equal(root.get("id"), request.getId()));	
			}		
			
			final Predicate[] pre = new Predicate[predicate.size()];
			return query.where(predicate.toArray(pre)).getRestriction();
		};
	}


}
